<# # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Endpoint Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description: Script is designed To Add a Local User to Local Group via Group SID # Configuration Type - COMPUTER # Arguments - The value needs to be hardcoded inside the script #> # Hard-coded values $username = "Test" # Replace with the actual username $groupSid = "S-1-5-32-544" # Replace with the actual group SID # Check if the user exists if (Get-LocalUser -Name $username -ErrorAction SilentlyContinue) { try { # Create a SecurityIdentifier object from the SID $sid = New-Object System.Security.Principal.SecurityIdentifier($groupSid) # Get the group by SID $group = Get-LocalGroup | Where-Object { $_.SID -eq $sid.Value } if ($group) { # Add user to group Add-LocalGroupMember -Group $group.Name -Member $username Write-Host "User '$username' has been added to the group with SID '$groupSid'." } else { Write-Host "Group with SID '$groupSid' does not exist." } } catch { Write-Host "Invalid SID format or error: $_" } } else { Write-Host "User '$username' does not exist." }